/**
 * ui界面执行算法需要调用的接口，
 * 负责进入AnalyticalProcessor和RayTracingProcessor将参数转存到算法层的数据结构中
 */

#ifndef UI_ALGORITHM_PROCESSOR_H
#define UI_ALGORITHM_PROCESSOR_H

#include <algorithm/analytical_model/algorithm/cuda/inter_op/Data.h>
#include <algorithm/analytical_model/io/FileTypes.h>

#include <QObject>
#include <QString>
#include <QQuickWindow>

#include <string_view>

#include <boost/json/value.hpp>

QT_BEGIN_NAMESPACE
class QQmlApplicationEngine;
QT_END_NAMESPACE

namespace solar
{
    class Scene;
    class RayTracingParameter;
    class RayTracingProcessor;
    class FluxMapParameter;
    class RayTracingPipeline;
    class SceneRendererAdapter;
    struct AnalyticalPipelineParam;

    class AlgorithmProcessor : public QObject
    {
            Q_OBJECT

            // Q_PROPERTY (QString input_file_path READ getInputFilePath WRITE setInputFilePath
            // NOTIFY inputFilePathChanged)

        public:
            AlgorithmProcessor(std::shared_ptr<Scene> scene,
                               std::shared_ptr<RayTracingParameter> simulation_paras,
                               std::shared_ptr<FluxMapParameter> flux_map_paras,
                               QQmlApplicationEngine* qml_engine
                               // std::shared_ptr<RayTracingProcessor> ray_tracing_processor
            );

            /**
             * 用于修改Q_OBJECT
             */
            // QString getInputFilePath();
            // void setInputFilePath(QString input_file_path);

            /**
             * 用于调用算法
             */
            // NOLINTBEGIN(modernize-use-trailing-return-type)
            Q_INVOKABLE bool runRayTracing();         // 执行rayTracing
            Q_INVOKABLE bool runAnalyticalFunction(); // 执行解析方法
            Q_INVOKABLE bool plotFluxMap();           // 画出结果

            Q_INVOKABLE bool runFile(); // 执行文件中定义的算法、场景参数
            Q_INVOKABLE float* getCudaDataImage();
            Q_INVOKABLE cuda::inter_op::Uchar4* getFluxMapData();
            Q_INVOKABLE void setJsonFilePath(const QString& path);

            void updateAnalyticalPipelineParam(const io::JSONType&);
            void updateScene();

            static constexpr auto algorithm_raytracing_ = 0;
            static constexpr auto algorithm_analytical_ = 1;
            static constexpr std::string_view algorithm_raytracing_str_ = "raytracing";
            static constexpr std::string_view algorithm_analytical_str_ = "analytical";
            // NOLINTEND(modernize-use-trailing-return-type)

            // signals:
            //     void inputFilePathChanged();

        private:
            // 根据rasult_data，把结果存入flux_map_paras_
            void updateFluxMapPara();

            // QString input_file_path_;
            int algorithm_type_ = algorithm_raytracing_; // 算法类型：0-raytracing  1-analytical  ------先暂时设置为0

            std::shared_ptr<Scene> scene_; // 场景---从场景中读取数据
            std::shared_ptr<RayTracingParameter> simulation_paras_; // 仿真参数
            std::shared_ptr<FluxMapParameter> flux_map_paras_; // 画flux map需要的相关参数

            std::shared_ptr<RayTracingProcessor> ray_tracing_processor_;
            // ResultData result_data_ ;
            std::shared_ptr<RayTracingPipeline> raytracing_pipeline_;
            std::shared_ptr<AnalyticalPipelineParam> analytical_pipeline_param_;
            QQmlApplicationEngine* qml_engine_;
            boost::json::value scene_json_value_;
            std::string json_file_path_;
    };
} // namespace solar

#endif
